﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Http;
using System.Threading;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using CCWin;

namespace SafeSave
{

    public partial class LoginForm : CCSkinMain
    {
        string address;
        string url;

        public LoginForm()
        {
            InitializeComponent();
        }


        private void skinLabel1_Click(object sender, EventArgs e)
        {
            RegisterForm reg = new RegisterForm();
            reg.Show();
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            try
            {
                HttpHelper httphelper = new HttpHelper();
                string req;
                if (loginTab.SelectedIndex == 0)
                {
                    LoginJobject_key loginObject = new LoginJobject_key();
                    loginObject.account_private_key = privateKeyBox.Text;
                    req = JsonConvert.SerializeObject(loginObject);//创建请求Json
                }
                else
                {
                    LoginJobject_account loginObject = new LoginJobject_account();
                    loginObject.account_address = usernameBox.Text;
                    loginObject.keyword = passwordBox.Text;
                    req = JsonConvert.SerializeObject(loginObject);//创建请求Json
                }

                url = this.urlBox.Text;

                string res = httphelper.HttpPost("http://"+url +"/sign_in", req);//返回的Json
                JObject jo = JObject.Parse(res);//返回的Json转为类
                address = jo.GetValue("account_address").ToString();

                MainForm mainform = new MainForm(address,url);
                mainform.Show();
                this.Hide();
            }
            catch
            {
                MessageBox.Show("连接出错");
            }
            //MainForm mainform = new MainForm(address,url);
            //mainform.Show();
            //this.Hide();

        }



    }

    
}
